<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <t:header title="Auctions for ${actionBean.teacher.fullName}"/>
    </head>
    <body>
        <div id="header">
            <div id="titleSection">
                <t:pageheader title="Auctions for ${actionBean.teacher.fullName}"/>
            </div>
        </div>
        <div id="contentPanel">
            <t:leftsidenav/>
            <div id="pageContent"  class="cell" style="padding-left: 10px;">
                <s:errors/>
                <s:form action="/ShowAuction.action">
                    <s:hidden name="auction.id"/>
                    <table class="leftRightForm">
                        <col /><col /><col />
                        <tr>
                            <td rowspan="2">
                                <c:set var="url" value=""/>
                                <c:choose>
                                    <c:when test="${!empty actionBean.auction.picBlob}">
                                        <s:url var="url" beanclass="pkg.action.ImageActionBean">
                                            <s:param name="auction.id" value="${actionBean.auction.id}"/>
                                            <s:param name="image"/>
                                        </s:url>
                                    </c:when>
                                    <c:when test="${!empty actionBean.teacher.picBlob}">
                                        <s:url var="url" beanclass="pkg.action.ImageActionBean">
                                            <s:param name="teacher.id" value="${actionBean.teacher.id}"/>
                                            <s:param name="image"/>
                                        </s:url>
                                    </c:when>
                                </c:choose>
                                <c:if test="${!empty url}">
                                    <img src="${url}" />
                                </c:if>
                            </td>
                            <td nowrap width="36%" style="padding-left: 10px;">
                                <div class="teacherTitle">${actionBean.auction.teacher.fullName}</div>
                                <div class="sectionTitle">${actionBean.auction.title}</div>
                                <p> Auction ends on <br /> <fmt:formatDate value="${actionBean.auction.endDate}" pattern="MM-dd-yyyy" timeZone="America/Los_Angeles"/> at
                                    <fmt:formatDate value="${actionBean.auction.endDate}" pattern="hh:mma" timeZone="America/Los_Angeles"/>.</p>
                            </td>
                            <td rowspan="2">${actionBean.auction.description}</td>
                        </tr>
                        <tr>
                            <td></td>
                        </tr>
                    </table>
                    <table style="width: 756px;">
                        <tr>
                            <td width="50%" style="vertical-align: top;">
                                <table style="width: 200px; margin: 0 auto;" class="bidTable">
                                    <tr><td colspan="2" style="text-align: center;"><div class="sectionTitle">Place Your Bid</div></td></tr>
                                    <tr>
                                        <th><s:label name="auction.amount">Current Amount:</s:label></th>
                                        <td><fmt:formatNumber type="currency" value="${actionBean.auction.amount}"/></td>
                                        <td><s:errors field="auction.amount"/></td>
                                    </tr>
                                    <tr>
                                        <th><s:label name="auction.increment">Bid Increment:</s:label></th>
                                        <td><fmt:formatNumber type="currency" value="${actionBean.auction.increment}"/></td>
                                        <td><s:errors field="auction.increment"/></td>
                                    </tr>
                                    <c:if test="${!empty user && actionBean.auction.biddable}">
                                        <tr>
                                            <th><s:label name="bid.amount">Your bid:</s:label></th>
                                            <td><s:text name="bid.amount" formatType="decimal" size="5" maxlength="8"/></td>
                                            <td></td>
                                        </tr>
                                    </c:if>
                                    <c:if test="${actionBean.auction.closed}">
                                        <tr>
                                            <td colspan="2">This auction is <b>CLOSED</b>.</td>
                                        </tr>
                                    </c:if>
                                    <c:if test="${not actionBean.auction.active}">
                                        <tr>
                                            <td colspan="2">${actionBean.auction.active} This auction is <b>NOT ACTIVE</b>.</td>
                                        </tr>
                                    </c:if>
                                    <tr>
                                        <td colspan="2" style="text-align: center;">
                                            <c:if test="${!empty user && actionBean.auction.biddable}">
                                                <div class="buttons">
                                                    <s:submit value="Bid" name="doBid"/>
                                                </div>
                                            </c:if>
                                            <c:if test="${empty user}">
                                                <p>Please <a href="/Register.action">register</a> to bid on this auction.</p>
                                            </c:if>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td>
                                <div class="sectionTitle" style="text-align: center;">Bid History</div>
                                <c:choose>
                                    <c:when test="${fn:length(actionBean.bids) == 0}">
                                        <p style="text-align: center">Enter the first bid!</p>
                                    </c:when>
                                    <c:otherwise>
                                        <dt:table uid="bidtable" list="${actionBean.bids}" id="obj" class="display" style="border: 1px solid #f1f1f1">
                                            <dt:column title="Bidder">
                                                ${obj.user.fullName}
                                            </dt:column>
                                            <dt:column style="padding-right: 10px;" title="Amount" property="amount" format="{0,number,currency}"/>
                                            <dt:column style="width: 150px;" title="Date">
                                                <fmt:formatDate pattern="MM-dd-yyyy hh:mma " timeZone="America/Los_Angeles" value="${obj.timestamp}"/>
                                            </dt:column>
                                        </dt:table>
                                    </c:otherwise>
                                </c:choose>
                            </td>
                        </tr>
                    </table>
                </s:form>
            </div>
            <div style="clear: both; padding-top: 15px;"></div>
        </div>
    </body>
</html>
